# -*- coding: utf-8 -*-
"""
Created on Thu Sep 12 16:40:38 2019

@author: Administrator
"""

# 1004 成绩排名
# 读入n>0名学生的姓名、学号、成绩，分别输出成绩最高和最低的学生的姓名和学号
# 输入格式：
# 3
# Joe Math990112 89
# Mike CS9901301 100
# 输出格式：
# Mike CSxx
# Joe Mathxx

def test():
    count = int(input())
    raw = []
    temp = []
    for index in range(count):
        raw.append(input())
    
    for index in range(count):
        temp.append(raw[index].split(' '))
        
    # 对学生的成绩排序
    max_index, min_index = grade_sort(temp)
    print(" ".join(temp[max_index][0:2]))
    print(" ".join(temp[min_index][0:2]))
    
def grade_sort(temp):
    count = len(temp)
    grade_max = 0
    grade_min = 100
    max_index = 0
    min_index = 0
    
    for index in range(count):
        if int(temp[index][2]) >= grade_max:
            grade_max = int(temp[index][2])
            max_index = index
            
        if int(temp[index][2]) <= grade_min:
            grade_min = int(temp[index][2])
            min_index = index
    return max_index, min_index

#temp = [['Joe', 'Math', '89'], 
#        ['Mike', 'CS', '100'],
#        ['Mary', 'EE', '78'],
#        ['Tony', 'EE', '60']]
#
#print(grade_sort(temp))

test();
